#ifndef DCMIMAGECACHE_H
#define DCMIMAGECACHE_H

#include <QCache>
#include <QObject>
#include <QMutex>
#include "imageinstance.h"

class DcmImageCache :public QObject
{
    Q_OBJECT
public:
    static DcmImageCache& getCacher();
    ImageInstance* getImage(const QString &key);
    void insertImage(ImageInstance *image);

private:
    DcmImageCache(QObject *parent = 0):QObject(parent){ cache.setMaxCost(1000); }
    ~DcmImageCache(){}
    Q_DISABLE_COPY(DcmImageCache)
    void doInsertImage(ImageInstance *image);

    class Releaser {
        ~Releaser() {
            if (inst) {
                delete inst;
                delete m;
            }
        }
    };

    static Releaser r;
    static QMutex *m;
    static DcmImageCache *inst;
    QCache<QString, ImageInstance> cache;
};

#endif // DCMIMAGECACHE_H
